<?php
/** 
 * Smarty implode function plugin
 *
 * Copyright(c) 2008 by GuanYongze. All rights reserved
 *
 * To contact the author write to GuanYongze@163.com
 *
 * @author 远帆 
 * @link mailto:GuanYongze@163.com 
 * @package system 
 * @filesource function.implode.php
 * @version $Id: xyz.php, v 1.0.0 2010-3-17 上午11:46:21 
 */

/**
 * Smarty {implode} function plugin
 *	
 * 用指定的字符去连接一个数组
 * 例：
 * 	$array = array('a', 'b', 'c');
 * 	{implode object=$array glue=', ' assign='$out'}
 * 	现在$out = a, b, b;
 * 
 *  如果要直接输出
 *  用 {implode subject=$array glue=','}
 *
 * @author 远帆 
 * @link mailto:GuanYongze@163.com 
 * @package system 
 * @filesource function.implode.php
 * @version $Id: xyz.php, v 1.0.0 2010-3-17 上午11:46:21 
 */
function smarty_function_implode($params, &$smarty)
{
	
    if (!isset($params['object'])) {
        $smarty->trigger_error("implode: missing 'object' parameter");
        return;
    }

    if (!isset($params['glue'])) {
        $smarty->trigger_error("implode: missing 'glue' parameter");
        return;
    }
	

    if (isset($params['assign'])) {
        $smarty->assign($params['assign'], implode($params['glue'], $params['object']));
    } else {
		echo implode($params['glue'], $params['object']);
	}
} 